package com.xb.system.controller;

import com.xb.model.domain.entity.PopupDetails;
import com.xb.system.common.result.Result;
import com.xb.system.service.PopupDetailsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/popup")
public class PopupDetailsController {
    private static final Logger log = LoggerFactory.getLogger(PopupDetailsController.class);
    @Autowired
    private PopupDetailsService popupDetailsService;

    /**
     * 获取广告弹窗详情
     * @return 广告弹窗列表
     */
    @GetMapping("/details")
    public Result<Object> getPopupDetails() {
        try {
            List<PopupDetails> popupList = popupDetailsService.getActivePopups();
            if (popupList != null && !popupList.isEmpty()) {
                return Result.ok(popupList);
            }
            return Result.fail("未找到有效的广告信息");
        } catch (Exception e) {
            return Result.fail("获取广告信息失败: " + e.getMessage());
        }
    }
    
    /**
     * 获取套餐信息
     * @return 套餐数据
     */
    @GetMapping("/packages")
    public Result<Object> getPackages() {
        try {
            Map<String, Object> packages = popupDetailsService.getActivePackages();
            return Result.ok(packages);
        } catch (Exception e) {
            log.error("获取套餐信息失败", e);
            return Result.fail("获取套餐信息失败: " + e.getMessage());
        }
    }
}